package com.vf.admin.miaodong.dao;

import com.vf.admin.common.db.BaseDao;
import com.vf.admin.common.splitpage.SplitPageBean;
import com.vf.admin.miaodong.entity.AppMingXiZuanShi;
import com.vf.admin.utils.StringEx;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * @author anxiang
 * @version 1.0.0
 * @ClassName AfterMingXiZuanShiDao.java
 * @Description 钻石明细记录
 * @createTime 2021年11月02日 12:51:00
 */
@Repository
public class AfterMingXiZuanShiDao extends BaseDao<AppMingXiZuanShi> {

    /**
     * 新增或更新
     * @param appMingXiZuanShi
     */
    public void saveOrUpdate(AppMingXiZuanShi appMingXiZuanShi) {
        if (appMingXiZuanShi.getId() == null || appMingXiZuanShi.getId() == 0) {
            appMingXiZuanShi.setId(this.add(appMingXiZuanShi));
        } else {
            this.update(appMingXiZuanShi);
        }
    }

    /**
     * 综合查询
     * @param paraMap
     * @param splitPageBean
     * @return
     */
    public List<AppMingXiZuanShi> findList(Map<String, Object> paraMap, SplitPageBean splitPageBean) {
        StringBuilder sbStr = new StringBuilder("select * from app_mingxi_zuanshi where 1=1 ");
        List<Object> paramList = new ArrayList<>();
        if(StringEx.isNotNull(paraMap.get("startDate"))){
            sbStr.append(" and DATE_FORMAT(createtime, '%Y-%m-%d')  >=  ? ");
            paramList.add(paraMap.get("startDate"));
        }
        if(StringEx.isNotNull(paraMap.get("endDate"))){
            sbStr.append(" and DATE_FORMAT(createtime, '%Y-%m-%d')  <=  ? ");
            paramList.add(paraMap.get("endDate"));
        }
        if(StringEx.isNotNull(paraMap.get("nick"))){
            sbStr.append(" and nick like ? ");
            paramList.add("%"+paraMap.get("nick")+"%");
        }
        if(StringEx.isNotNull(paraMap.get("phone"))){
            sbStr.append(" and phone = ? ");
            paramList.add(paraMap.get("phone"));
        }
        if(paraMap.containsKey("userid") && StringEx.isNotNull(paraMap.get("userid"))){
            sbStr.append(" and userid = ? ");
            paramList.add(paraMap.get("userid"));
        }
        sbStr.append(" order by createtime desc ");
        String sql = sbStr.toString();
        return this.queryList(sql, paramList, AppMingXiZuanShi.class, splitPageBean);
    }

    public List<AppMingXiZuanShi> findTeamList(Map<String, Object> paraMap, SplitPageBean splitPageBean) {
        StringBuilder sbStr = new StringBuilder("select * from app_mingxi_zuanshi where 1=1 ");
        List<Object> paramList = new ArrayList<>();
        if(StringEx.isNotNull(paraMap.get("startDate"))){
            sbStr.append(" and DATE_FORMAT(createtime, '%Y-%m-%d')  >=  ? ");
            paramList.add(paraMap.get("startDate"));
        }
        if(StringEx.isNotNull(paraMap.get("endDate"))){
            sbStr.append(" and DATE_FORMAT(createtime, '%Y-%m-%d')  <=  ? ");
            paramList.add(paraMap.get("endDate"));
        }
        if(StringEx.isNotNull(paraMap.get("nick"))){
            sbStr.append(" and nick like ? ");
            paramList.add("%"+paraMap.get("nick")+"%");
        }
        if(StringEx.isNotNull(paraMap.get("phone"))){
            sbStr.append(" and phone = ? ");
            paramList.add(paraMap.get("phone"));
        }
        if(StringEx.isNotNull(paraMap.get("tUserId"))){
            sbStr.append(" and userId = ? ");
            paramList.add(paraMap.get("tUserId"));
        }
        if(paraMap.containsKey("userids") && StringEx.isNotNull(paraMap.get("userids"))){
            sbStr.append(" and userid in ( ");
            sbStr.append(paraMap.get("userids"));
            sbStr.append(" ) ");
        }
        sbStr.append(" order by createtime desc ");
        String sql = sbStr.toString();
        return this.queryList(sql, paramList, AppMingXiZuanShi.class, splitPageBean);
    }

    public List<AppMingXiZuanShi> findTeamListSum(Map<String, Object> paraMap) {
        StringBuilder sbStr = new StringBuilder("select * from app_mingxi_zuanshi where 1=1 ");
        List<Object> paramList = new ArrayList<>();
        if(StringEx.isNotNull(paraMap.get("startDate"))){
            sbStr.append(" and DATE_FORMAT(createtime, '%Y-%m-%d')  >=  ? ");
            paramList.add(paraMap.get("startDate"));
        }
        if(StringEx.isNotNull(paraMap.get("endDate"))){
            sbStr.append(" and DATE_FORMAT(createtime, '%Y-%m-%d')  <=  ? ");
            paramList.add(paraMap.get("endDate"));
        }
        if(StringEx.isNotNull(paraMap.get("nick"))){
            sbStr.append(" and nick like ? ");
            paramList.add("%"+paraMap.get("nick")+"%");
        }
        if(StringEx.isNotNull(paraMap.get("phone"))){
            sbStr.append(" and phone = ? ");
            paramList.add(paraMap.get("phone"));
        }
        if(StringEx.isNotNull(paraMap.get("tUserId"))){
            sbStr.append(" and userId = ? ");
            paramList.add(paraMap.get("tUserId"));
        }
        if(paraMap.containsKey("userids") && StringEx.isNotNull(paraMap.get("userids"))){
            sbStr.append(" and userid in ( ");
            sbStr.append(paraMap.get("userid"));
            sbStr.append(" ) ");
        }
        sbStr.append(" order by createtime desc ");
        String sql = sbStr.toString();
        return this.queryList(sql, paramList, AppMingXiZuanShi.class);
    }

}